package vip.sweet.sys.modular.opera.handler;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import vip.sweet.sys.modular.opera.entity.SysOperaLog;
import vip.sweet.sys.modular.opera.service.SysOperaLogService;

/**
 * @author ASUS
 * @Date 2025/4/29 17:02
 * @Descripition 清理日志任务
 */
@Slf4j
@Component
public class ClearOperaLogJobHandler {
    @Resource
    private SysOperaLogService sysOperaLogService;
    @Scheduled(cron = "0 30 9 1 * ?") // 每月1号9:30执行
//    @Scheduled(cron = "0 * * * * ?")
    public void clearLoginLog() {
        log.info("开始清理上个月操作日志");
        LambdaQueryWrapper<SysOperaLog> queryWrapper = new LambdaQueryWrapper<>();
        // 30天前
        queryWrapper.lt(SysOperaLog::getOperaTime, System.currentTimeMillis() - 30L * 24 * 60 * 60 * 1000);
        // 删除
        sysOperaLogService.remove(queryWrapper);
        log.info("清理登录日志完成");
    }

}
